package com.jade.linkong.service.impl;

import com.jade.common.core.domain.Ztree;
import com.jade.common.core.text.Convert;
import com.jade.common.utils.DateUtils;
import com.jade.linkong.domain.LkProjectTag;
import com.jade.linkong.mapper.LkProjectTagMapper;
import com.jade.linkong.service.ILkProjectTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目标签Service业务层处理
 * 
 * @author jade
 * @date 2020-08-05
 */
@Service
public class LkProjectTagServiceImpl implements ILkProjectTagService 
{
    @Autowired
    private LkProjectTagMapper lkProjectTagMapper;

    /**
     * 查询项目标签
     * 
     * @param tabId 项目标签ID
     * @return 项目标签
     */
    @Override
    public LkProjectTag selectLkProjectTagById(Long tabId)
    {
        return lkProjectTagMapper.selectLkProjectTagById(tabId);
    }

    /**
     * 查询项目标签列表
     * 
     * @param lkProjectTag 项目标签
     * @return 项目标签
     */
    @Override
    public List<LkProjectTag> selectLkProjectTagList(LkProjectTag lkProjectTag)
    {
        return lkProjectTagMapper.selectLkProjectTagList(lkProjectTag);
    }

    /**
     * 新增项目标签
     * 
     * @param lkProjectTag 项目标签
     * @return 结果
     */
    @Override
    public int insertLkProjectTag(LkProjectTag lkProjectTag)
    {
        lkProjectTag.setCreateTime(DateUtils.getNowDate());
        return lkProjectTagMapper.insertLkProjectTag(lkProjectTag);
    }

    /**
     * 修改项目标签
     * 
     * @param lkProjectTag 项目标签
     * @return 结果
     */
    @Override
    public int updateLkProjectTag(LkProjectTag lkProjectTag)
    {
        lkProjectTag.setUpdateTime(DateUtils.getNowDate());
        return lkProjectTagMapper.updateLkProjectTag(lkProjectTag);
    }

    /**
     * 删除项目标签对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLkProjectTagByIds(String ids)
    {
        return lkProjectTagMapper.deleteLkProjectTagByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除项目标签信息
     * 
     * @param tabId 项目标签ID
     * @return 结果
     */
    @Override
    public int deleteLkProjectTagById(Long tabId)
    {
        return lkProjectTagMapper.deleteLkProjectTagById(tabId);
    }

    /**
     * 查询项目标签树列表
     * 
     * @return 所有项目标签信息
     */
    @Override
    public List<Ztree> selectLkProjectTagTree()
    {
        List<LkProjectTag> lkProjectTagList = lkProjectTagMapper.selectLkProjectTagList(new LkProjectTag());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (LkProjectTag lkProjectTag : lkProjectTagList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(lkProjectTag.getTabId());
            ztree.setpId(lkProjectTag.getParentId());
            ztree.setName(lkProjectTag.getTabName());
            ztree.setTitle(lkProjectTag.getTabName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
